package net.wanho.controller;


import net.wanho.po.GoodsAttr;
import net.wanho.service.GoodsAttrService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import lombok.RequiredArgsConstructor;



import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 商品-属性关联表 前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2025-09-25
 */
@Api(tags = "商品属性关联表接口")
@RestController
@RequestMapping("/goods-attr")
@RequiredArgsConstructor
public class GoodsAttrController {

    private final GoodsAttrService goodsAttrService;

    @ApiOperation("商品-属性关联表分页查询")
    @GetMapping("/list")
    public AjaxResult findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") int pageNum,
                              @ApiParam("页大小") @RequestParam(defaultValue = "5") int pageSize,
                              @ApiParam("查询条件") GoodsAttr goodsAttr){
        PageInfo<GoodsAttr> pageInfo = goodsAttrService.findPage(pageNum,pageSize,goodsAttr);
        return AjaxResult.success(pageInfo);
    }

    @ApiOperation("根据主键查询商品-属性关联表")
    @GetMapping("/{id}")
    public AjaxResult findById(@PathVariable Serializable id){
        return AjaxResult.success(goodsAttrService.findById(id));
    }

    @ApiOperation("新增商品-属性关联表")
    @PostMapping
    public AjaxResult add(@RequestBody GoodsAttr goodsAttr){
        goodsAttrService.add(goodsAttr);
        return AjaxResult.success();
    }

    @ApiOperation("修改商品-属性关联表")
    @PutMapping
    public AjaxResult modify(@RequestBody GoodsAttr goodsAttr){
        goodsAttrService.modify(goodsAttr);
        return AjaxResult.success();
    }

    @ApiOperation("根据主键删除商品-属性关联表")
    @DeleteMapping("/{id}")
    public AjaxResult removeById(@PathVariable Serializable id){
        goodsAttrService.removeById(id);
        return AjaxResult.success();
    }

}
